﻿#ifndef STATISTICSTABLEMODEL_H
#define STATISTICSTABLEMODEL_H

#include <QAbstractTableModel>
#include <QJsonObject>
#include <QJsonArray>
#include <QStringList>

class StatisticsTableModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit StatisticsTableModel(QObject *parent = nullptr);
    void setJsonData(const QJsonObject &jsonData);
    void addRecord(const QJsonObject &newRecord);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

private:
    QJsonArray m_dataArray;  // 存储 JSON 数据的数组
    QStringList m_headers;   // 列表头
    QStringList m_rowHeaders; // 行表头
    QJsonObject calculateRowStatistics(const QJsonObject &rowData) const;
    QJsonObject calculateColumnStatistics() const;
};

#endif // STATISTICSTABLEMODEL_H
